/**
 * 
 */

package com.shy.portal.dao.impl;

import java.util.List;

import javax.persistence.Query;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.shy.base.dao.impl.BaseDaoImpl;
import com.shy.portal.dao.UserRoleDao;
import com.shy.portal.entity.UserRole;

/**
 * <p>
 * Title:UserRoleDaoImpl
 * </p>
 * <p>
 * Description:
 * </p>
 * <p>
 * Company:ipebg
 * </p>
 * 
 * @author H2013788
 */
@Repository("userRoleDao")
public class UserRoleDaoImpl extends BaseDaoImpl<UserRole> implements UserRoleDao {

	/**
     * log
     */
	private Logger logger = LogManager.getLogger(this.getClass());

    @Transactional
    @Override
    public boolean batchSaveUserRole(List<UserRole> list, Integer userId) throws Exception {
        try {
            // 刪除原有
            String hql = " delete from UserRole where user.id=:userId ";
            Query query = entityManager.createQuery(hql);
            query.setParameter("userId", userId);
            query.executeUpdate();
            // 批量添加
            batchSave(list);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("batch save RoleMenu error : " + e);
            throw e;
        }
    }

}
